package org.zxl.iotest.netty.protobuf.server;

import io.netty.buffer.ByteBuf;
import org.zxl.iotest.netty.protobuf.util.ByteUtils;
import org.zxl.iotest.netty.protobuf.util.ZxlMsg;

/**
 * @author zhangxiaolong
 * @date 2025-02-16 18:00
 **/
public class ServerMessageParse {
    public static ZxlMsg parse(ByteBuf buf) {
        byte[] msgIdBytes = new byte[4];
        buf.readBytes(msgIdBytes);
        int msgId = ByteUtils.bytesToIntBE(msgIdBytes);
        System.out.println("msgId:"+msgId);

        byte[] msgLengthBytes = new byte[4];
        buf.readBytes(msgLengthBytes);
        int msgLength = ByteUtils.bytesToIntBE(msgLengthBytes);
        System.out.println("msgLength:"+msgLength);

        return new ZxlMsg(msgId, msgLength);
    }
}
